package com.ld.control.business.equipment.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ld.control.business.equipment.mapper.EquipmentDataFieldConfigMapper;
import com.ld.control.business.equipment.model.EquipmentDataFieldConfigModel;
import com.ld.control.business.equipment.service.EquipmentDataFieldConfigService;
import com.ld.control.business.equipment.service.EquipmentService;
import com.ld.control.business.equipment.vo.req.EquipmentDataFieldConfigReqVo;
import com.ld.control.business.equipment.vo.resp.EquipmentDataFieldConfigRespVo;
import com.ld.control.business.equipment.vo.resp.EquipmentRespVo;
import com.ld.control.common.vo.GenerateListVo;
import com.ld.control.common.vo.GeneratePageListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangfeng
 * @since 2025-01-09
 */
@Service
public class EquipmentDataFieldConfigServiceImpl extends ServiceImpl<EquipmentDataFieldConfigMapper, EquipmentDataFieldConfigModel> implements EquipmentDataFieldConfigService {

    @Autowired
    private EquipmentDataFieldConfigMapper equipmentDataFieldConfigMapper;

    @Autowired
    private EquipmentService equipmentService;

    @Override
    public void add(EquipmentDataFieldConfigReqVo  reqVo) {
        EquipmentDataFieldConfigModel equipmentDataFieldConfigModel = new EquipmentDataFieldConfigModel();
        BeanUtils.copyProperties(reqVo, equipmentDataFieldConfigModel);
        equipmentDataFieldConfigMapper.insert(equipmentDataFieldConfigModel);
    }

    @Override
    public void updateById(EquipmentDataFieldConfigReqVo reqVo) {
        EquipmentDataFieldConfigModel equipmentDataFieldConfigModel = new EquipmentDataFieldConfigModel();
        BeanUtils.copyProperties(reqVo, equipmentDataFieldConfigModel);
        equipmentDataFieldConfigMapper.updateById(equipmentDataFieldConfigModel);
    }

    @Override
    public void deleteById(Long id) {
        equipmentDataFieldConfigMapper.deleteById(id);
    }

    @Override
    public EquipmentDataFieldConfigRespVo getById(Long id) {
        EquipmentDataFieldConfigRespVo equipmentDataFieldConfigRespVo = new EquipmentDataFieldConfigRespVo();
        EquipmentDataFieldConfigModel equipmentDataFieldConfigModel = equipmentDataFieldConfigMapper.selectById(id);
        BeanUtils.copyProperties(equipmentDataFieldConfigModel, equipmentDataFieldConfigRespVo);
        return equipmentDataFieldConfigRespVo;
    }

    @Override
    public GenerateListVo<EquipmentDataFieldConfigRespVo> getList(Long equipmentId) {
        List<EquipmentDataFieldConfigRespVo> equipmentDataFieldConfigRespVoList = equipmentDataFieldConfigMapper.selectListByEquipmentId(equipmentId);
        Map<Long, EquipmentRespVo> equipmentRespVoAllMap = equipmentService.getEquipmentRespVoAllMap();
        for (EquipmentDataFieldConfigRespVo respVo : equipmentDataFieldConfigRespVoList) {
            EquipmentRespVo equipmentRespVo = equipmentRespVoAllMap.get(respVo.getEquipmentId());
            respVo.setEquipmentName(equipmentRespVo.getName());
        }
        return new GenerateListVo<>(equipmentDataFieldConfigRespVoList);
    }
}
